package com.fh.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectResult;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;


public class FileUploadUtils {
    private static final String  endpoint = "oss-cn-qingdao.aliyuncs.com";
    private static final String  accessKeyId = "LTAI5tKH5sSDLHXM19YvW4Nc";
    private static final String   accessKeySecret = "LeK5swUaVPR70rQtBgNpeYtAbanTeg";
    private static final String bucket="yyq-2104";

    public static String uploadFileOss(InputStream is,String name) throws Exception{
        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        // 依次填写Bucket名称（例如examplebucket）和Object完整路径（例如exampledir/exampleobject.txt）。Object完整路径中不能包含Bucket名称。
        PutObjectResult putObjectResult = ossClient.putObject(bucket, name, is);
        System.out.println(putObjectResult);
        // 关闭OSSClient。
        ossClient.shutdown();
        return "https://"+bucket+"."+endpoint+"//"+name;
    }


}
